<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			let students=[]
			function init(){
				let xhr=new XMLHttpRequest()
				xhr.open("GET","stus.xml",false)
				xhr.send()
				let data=xhr.responseXML
				students = data.querySelectorAll("student")
				document.getElementById("number1").value=students[0].getAttribute("sno")
				document.getElementById("name").value=students[0].getAttribute("sname")
			}
		</script>
	</head>
	<body onload="init()">
		学号:<input type="text" id="number1"/><br>
		姓名:<input type="text" id="name"/>
		<button type="button" >下一个</button>
		
		<script type="text/javascript">
			let index=1
			
			document.querySelector("button").onclick=function(){
				index++
				if(index>students.length){
					index=1//第n个学生 不是下标(0)
				}
				document.getElementById("number1").value=students[index-1].getAttribute("sno")
				document.getElementById("name").value=students[index-1].getAttribute("sname")
			}
		</script>
		
	</body>
</html>
